#!/bin/sh

VERBOSITY=1
CONFIG="/etc/cirros-init/ds-none"
NAME="${0##*/}"

. ${CIRROS_SHLIB:=/lib/cirros/shlib} ||
	{ echo "failed to read ${CIRROS_SHLIB}" 1>&2; exit 1; }

Usage() {
	cat <<EOF
Usage: ${0##*/} mode output_d

   The 'none' datasource.

   This is always "found" and does nothing.
EOF
}

search_local() {
	local out_d="$1"
	local data_d="${out_d}/data"
	[ -d "$out_d" ] || mkdir -p "$out_d" ||
		{ error "failed to create output dir"; return 1; }
	echo "i-dsnone" > "${data_d}/instance-id"
	echo 0 > "$out_d/result"
}

apply() {
	return 0
}

short_opts="hv"
long_opts="help,verbose"
getopt_out=$(getopt --name "${0##*/}" \
	--options "${short_opts}" --long "${long_opts}" -- "$@") &&
	eval set -- "${getopt_out}" ||
	bad_Usage

while [ $# -ne 0 ]; do
	cur=${1}; next=${2};
	case "$cur" in
		-h|--help) Usage ; exit 0;;
		-v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
		--) shift; break;;
	esac
	shift;
done

[ $# -eq 2 ] || bad_Usage "must provide mode and output dir"
mode="$1"
out_d="$2"

[ "$mode" = "local" -o "$mode" = "apply-local" ] ||
	{ debug 2 "only supported in mode 'local'"; exit 0; }

[ ! -e "$CONFIG" ] || . "$CONFIG" ||
	fail "failed to read $CONFIG"

if [ "$mode" = "local" ]; then
	search_local "$out_d"
elif [ "$mode" = "apply-local" ]; then
	apply "$mode" "$out_d"
else
	fail "error, unexpected input"
fi

exit
# vi: ts=4 noexpandtab
